using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace QuanLyNganHangDe.DAL.Models.Mapping
{
    public class CauHoiMap : EntityTypeConfiguration<CauHoi>
    {
        public CauHoiMap()
        {
            // Primary Key
            this.HasKey(t => t.MaCauHoi);

            // Properties
            this.Property(t => t.MaCauHoi)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.TenCauHoi)
                .HasMaxLength(50);

            this.Property(t => t.MaKhoi)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.TenDangNhap)
                .IsRequired()
                .HasMaxLength(50);

            // Table & Column Mappings
            this.ToTable("CauHoi");
            this.Property(t => t.MaCauHoi).HasColumnName("MaCauHoi");
            this.Property(t => t.TenCauHoi).HasColumnName("TenCauHoi");
            this.Property(t => t.NoiDungCauHoi_Unicode).HasColumnName("NoiDungCauHoi_Unicode");
            this.Property(t => t.NoiDungCauHoi_RTF).HasColumnName("NoiDungCauHoi_RTF");
            this.Property(t => t.NoiDungTraLoi_Unicode).HasColumnName("NoiDungTraLoi_Unicode");
            this.Property(t => t.NoiDungTraLoi_RTF).HasColumnName("NoiDungTraLoi_RTF");
            this.Property(t => t.MaKhoi).HasColumnName("MaKhoi");
            this.Property(t => t.TenDangNhap).HasColumnName("TenDangNhap");
            this.Property(t => t.ConSuDung).HasColumnName("ConSuDung");

            // Relationships
            this.HasMany(t => t.DeInRaCollection)
                .WithMany(t => t.CauHoiCollection)
                .Map(m =>
                    {
                        m.ToTable("DeInRa_CauHoi");
                        m.MapLeftKey("MaCauHoi");
                        m.MapRightKey("MaDeThi");
                    });

            this.HasRequired(t => t.Khoi)
                .WithMany(t => t.CauHoiCollection)
                .HasForeignKey(d => d.MaKhoi);
            this.HasRequired(t => t.NguoiSuDung)
                .WithMany(t => t.CauHoiCollection)
                .HasForeignKey(d => d.TenDangNhap);

        }
    }
}
